package com.oa.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oa.server.entity.Menu;
import com.oa.server.entity.MenuRole;
import com.oa.server.mapper.MenuRoleMapper;
import com.oa.server.result.ResponseBean;
import com.oa.server.service.IMenuRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mcy
 * @since 2021-06-01
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements IMenuRoleService {

    @Autowired
    private MenuRoleMapper menuRoleMapper;
    @Override
    @Transactional
    public ResponseBean updateMenuRole(Integer rid, Integer[] mids) {
        // 先删除后查询
        menuRoleMapper.delete(new QueryWrapper<MenuRole>().eq("rid",rid));
        if(null ==mids ||0 == mids.length){
            return ResponseBean.success("更新成功");
        }
        // 批量更新 insert

        Integer result = menuRoleMapper.insertRecoed(rid, mids);
        if(result == mids.length){
            return ResponseBean.success("更新成功");
        }
        return ResponseBean.success("更新失败");
    }
}
